Skip to content

fix(android): forward-split auth and EPUB security from PR 108 - #113

Merged
RXWatcher merged 17 commits into
mainfrom
split/108-b-auth-epub
Jul 27, 2026
Merged

fix(android): forward-split auth and EPUB security from PR 108#113
RXWatcher merged 17 commits into
mainfrom
split/108-b-auth-epub

Conversation

@RXWatcher

@RXWatcher RXWatcher commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Stack

Scope

A coherent auth/origin/cleartext + EPUB-security vertical slice:

  • exact Silo HTTP-origin parsing and credential scoping across requests, redirects, refresh, and media transports
  • persistent and temporary credential-generation pinning, including same-server re-login and guest-overlay races
  • explicit cleartext consent on mobile/TV, enforced at setup, startup, shared Ktor, media, pairing persistence, and every raw-player redirect/follow-up
  • bounded remote/archive/markup reads, ZIP extraction controls, parsed EPUB sanitization, SVG restrictions, and API-24-compatible paths
  • WebView resource isolation bound to the exact open content-addressed EPUB directory, plus reader source remounting

Independent security-review corrections

The initial read-only review found five Important issues; this branch closes all five with regressions:

  1. legacy HTTP accounts and pairing/media bypasses now hit the central consent invariant;
  2. startup-loaded persistent credentials use a non-sentinel epoch;
  3. media auth pins the complete AuthScopeSnapshot and rejected guest refreshes cannot expose the saved owner;
  4. EPUB resources are native/JS-bound to one exact cached book;
  5. container/package/chapter markup has strict type-specific limits and section metadata reads only a bounded prefix.

Two follow-up reviews identified and this branch also closes:

  • absolute skip-auth login/poll/remote-auth candidates are checked by their actual request URL;
  • malformed lexical http: targets fail closed;
  • direct Media3 DataSpec requests and every OkHttp redirect/follow-up validate the final cleartext origin before credentials or transport.

Final independent follow-up security review of the final behavior (rebased code commit a07066a1): Critical 0 / Important 0 / Minor 0 — Ready: Yes.

Verification

  • scripts/check-build-supply-chain.sh
  • focused auth/origin/cleartext/media/pairing/EPUB regression suites
  • ./gradlew -Dorg.gradle.jvmargs="-Xmx4g -Dfile.encoding=UTF-8" testDebugUnitTest :androidApp:assembleRelease :androidTvApp:assembleRelease --max-workers=2 --no-daemon
  • Final post-fix result: BUILD SUCCESSFUL (3m56s; 325 tasks)
  • git diff --check; clean worktree

Traceability, conflict decisions, original PR108 commit references, and verification history are in docs/notes/2026-07-27-pr108-slice-b-traceability.md.

Summary by CodeRabbit

  • New Features

    • Added cleartext HTTP connection consent prompts for Android and Android TV.
    • Improved authentication and redirect handling to prevent credential leakage across origins.
    • Added EPUB security protections, including safer sanitization, resource isolation, extraction limits, and private app-assets loading.
    • Added reader input and subtitle size limits.
  • Bug Fixes

    • Prevented stale credentials from being reused after server or session changes.
    • Improved handling of unauthorized cross-origin media requests.
  • Tests

    • Expanded coverage for consent flows, authentication boundaries, reader security, and content limits.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: daf98140-198d-4ef2-83dd-14494b35d28e

📥 Commits

Reviewing files that changed from the base of the PR and between 4458e9d and 06a775a.

📒 Files selected for processing (61)
  • android-shared/build.gradle.kts
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/di/PlayerModule.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/io/LimitedStreams.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/network/CleartextConsentStore.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/pairing/PairingAuthPort.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/AuthenticatedDataSourceFactory.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaAuthInterceptor.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaAuthSession.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/PlayerOkHttpClient.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/io/LimitedStreamsTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/network/CleartextConsentStoreTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/pairing/RegistryPairingAuthPortTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/AuthenticatedDataSourceFactoryTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/MediaAuthInterceptorTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/MediaAuthSessionTest.kt
  • androidApp/build.gradle.kts
  • androidApp/gradle.lockfile
  • androidApp/src/androidMain/assets/reader/reflow/paginator.js
  • androidApp/src/androidMain/assets/reader/reflow/reader.html
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/MainActivity.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/di/AndroidModule.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/auth/ServerSetupScreen.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/auth/ServerSetupViewModel.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/reader/EpubBook.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/reader/ReaderFileCache.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/reader/reflow/EpubHtmlSanitizer.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/reader/reflow/EpubReflowSource.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/reader/reflow/EpubResourcePathHandler.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/reader/reflow/ReflowWebView.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/reader/reflow/ReflowableReader.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/reader/reflow/ReflowableSource.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/auth/ServerSetupPersistenceTest.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/reader/EpubBookTest.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/reader/ReaderEngineHostSourceTest.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/reader/ReaderFileCacheTest.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/reader/ReaderFileResolverTest.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/reader/ReflowWebViewEpubResourceTest.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/reader/reflow/EpubHtmlSanitizerTest.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/reader/reflow/EpubReflowSourceTest.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/reader/reflow/EpubResourcePathHandlerTest.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/MainTvActivity.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/di/AndroidTvModule.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/auth/TvServerSetupScreen.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/auth/TvServerSetupViewModel.kt
  • androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/auth/TvServerSetupPersistenceTest.kt
  • baselineprofile/gradle.lockfile
  • docs/notes/2026-07-27-pr108-slice-b-traceability.md
  • docs/superpowers/plans/2026-07-27-pr108-slice-b-auth-epub.md
  • gradle/libs.versions.toml
  • gradle/verification-metadata.xml
  • shared/src/androidMain/kotlin/org/siloserver/silo/network/EncryptedTokenManagerImpl.kt
  • shared/src/androidUnitTest/kotlin/org/siloserver/silo/network/EncryptedTokenManagerScopeGenerationTest.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/di/NetworkModule.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/network/AuthInterceptorImpl.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/network/AuthScopeSnapshot.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/network/CleartextOriginConsent.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/network/HttpOriginPolicy.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/network/SiloHttpClientImpl.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/network/TokenManager.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/network/HttpOriginPolicyTest.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/network/SiloAuthPluginPinTest.kt

📝 Walkthrough

Walkthrough

The PR adds cleartext-origin consent across Android, TV, pairing, and media authentication; introduces scope-aware credential refresh safeguards; enforces bounded reader and EPUB extraction; and isolates sanitized EPUB content through a restricted WebView asset pipeline.

Changes

Authentication and cleartext consent

Layer / File(s) Summary
Origin approval and setup confirmation
shared/src/commonMain/kotlin/org/siloserver/silo/network/*, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/network/*, androidApp/.../auth/*, androidTvApp/.../auth/*
HTTP origins are normalized and persisted as digests; Android and TV setup flows stage HTTP connections for confirmation before persistence or navigation.
Scoped authentication and refresh
shared/src/commonMain/kotlin/org/siloserver/silo/network/*, shared/src/androidMain/kotlin/org/siloserver/silo/network/EncryptedTokenManagerImpl.kt
Credential snapshots track identity and credential epochs, while refresh, retry, save, and invalidation operations remain bound to the captured server scope.
Media transport policy
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/*
Media requests enforce cleartext approval, scope credentials to matching origins, strip credentials on cross-origin redirects, and limit subtitle normalization to 32 MiB.
Reader input and EPUB extraction limits
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/io/LimitedStreams.kt, androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/reader/*
Bounded stream utilities enforce reader cache, chapter, archive entry, total extraction, and compression-ratio limits with cleanup on failures.
Sanitized EPUB WebView resources
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/reader/reflow/*, androidApp/src/androidMain/assets/reader/reflow/*
Jsoup sanitization, private app-assets URLs, CSP, path validation, symlink rejection, and shell navigation restrictions are added for reflow content.
Build and verification support
gradle/*, androidApp/*, baselineprofile/*, docs/*
Jsoup, AndroidX WebKit, test dependencies, lock entries, verification hashes, and Slice B traceability documents are added.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SetupViewModel
  participant CleartextConsentStore
  participant MediaAuthSession
  participant PlayerOkHttpClient
  participant EPUBWebView
  SetupViewModel->>CleartextConsentStore: check or approve HTTP origin
  CleartextConsentStore-->>SetupViewModel: approval state
  SetupViewModel->>MediaAuthSession: create session with consent
  MediaAuthSession->>PlayerOkHttpClient: authorize approved transport
  PlayerOkHttpClient->>EPUBWebView: serve scoped EPUB resources
Loading

Possibly related PRs

Suggested reviewers: quick104

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch split/108-b-auth-epub

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@RXWatcher
RXWatcher force-pushed the split/108-b-auth-epub branch from 1ace4ea to 06a775a Compare July 27, 2026 08:39
Base automatically changed from split/108-a-supply-chain to main July 27, 2026 16:35
@RXWatcher
RXWatcher marked this pull request as ready for review July 27, 2026 16:37
@RXWatcher
RXWatcher merged commit 8152189 into main Jul 27, 2026
2 checks passed
@RXWatcher
RXWatcher deleted the split/108-b-auth-epub branch July 27, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant